package com.baimifan.renovation.adapter;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.baimifan.renovation.R;
import com.baimifan.renovation.model.DemoData;
import com.baimifan.renovation.view.DemoHolder;

import org.xutils.common.util.DensityUtil;
import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by baimifan on 2017/07/04.
 */

public class DemoAdapter extends RecyclerView.Adapter<DemoHolder> {
    private ArrayList<DemoData> mlists;
    private Float w, h;
    private ImageOptions imageOptions;
    public DemoAdapter (ArrayList<DemoData> lists, Float w, Float h) {
        this.mlists = lists;
        this.w = w;
        this.h = h;
        imageOptions = new ImageOptions.Builder().setRadius(DensityUtil.dip2px(2)).
                build();
    }

    @Override
    public DemoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.demo_item, parent, false);
        DemoHolder demoHolder = new DemoHolder(view);
        return demoHolder;
    }

    @Override
    public void onBindViewHolder(DemoHolder holder, int position) {
        FrameLayout.LayoutParams params_iv = new FrameLayout.LayoutParams((int)(w*163), (int)(h*90));
        holder.iv.setLayoutParams(params_iv);
        FrameLayout.LayoutParams params_ll = new FrameLayout.LayoutParams((int)(w*163), (int)(h*24));
        params_ll.setMargins(0, (int)(h*66), 0, 0);
        holder.ll.setLayoutParams(params_ll);
        holder.ll.setAlpha((float) 0.32);
        GradientDrawable gd = new GradientDrawable();
        gd.setColor(Color.parseColor("#000000"));
        float[] radii = new float[] {0, 0, DensityUtil.dip2px(2),DensityUtil.dip2px(2),DensityUtil.dip2px(2),DensityUtil.dip2px(2),0,0,};
        gd.setCornerRadii(radii);
        holder.ll.setBackground(gd);
        FrameLayout.LayoutParams params_tv = new FrameLayout.LayoutParams((int)(w*163), (int)(h*24));
        params_tv.setMargins((int)(w*7), (int)(h*70), (int)(w*5),0);
        holder.title.setLayoutParams(params_tv);
        x.image().bind(holder.iv, mlists.get(position).getImg(),imageOptions);
        holder.title.setText(mlists.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return mlists.size();
    }


}
